package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Api(tags = "下单和微信支付")
@RequestMapping("/user/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 用户下单
     *
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result<OrderSubmitVO> PlaceOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        log.info("下单信息{}", ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 小程序支付
     */
    //TODO 没有完成
    @PutMapping("/payment")
    @ApiOperation("小程序支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO dto) {
        OrderPaymentVO ordersPaymentVO = orderService.payment(dto);
        return Result.success(ordersPaymentVO);
    }
    /**
     * 获取用户送餐期望时间
     */
    //TODO 报空指针
    @GetMapping("/getEstimatedDeliveryTime")
    @ApiOperation("获取用户送餐期望时间")
    public Result<String> getEstimatedDeliveryTime(Long shopId, String customerAddress) {
        String dateTime = orderService.getEstimatedDeliveryTime(shopId, customerAddress);
        return Result.success(dateTime);
    }
    /**
     * 历史订单查询
     */
    //TODO 没有完成,Status为空
    @GetMapping("/historyOrders")
    @ApiOperation("历史订单查询")
    public Result<PageResult> page(int page, int pageSize, Integer Status) {
        OrdersPageQueryDTO ordersPageQueryDTO = new OrdersPageQueryDTO();
        ordersPageQueryDTO.setPage(page);
        ordersPageQueryDTO.setPageSize(pageSize);
        ordersPageQueryDTO.setStatus(Status);
        log.info("输出对象{}", ordersPageQueryDTO);
        PageResult pageResult = orderService.pageQueryUser(ordersPageQueryDTO);
        return Result.success(pageResult);
    }
}
